/**
 * 
 */
package graph;

import graph.net.Ps1Server;
import graph.service.GraphService;
import graph.service.NoSuchRouteException;

/**
 * @author amahmood
 * 
 */
public class MainApp
{

    /**
     * @param args
     */
    public static void main(String[] args)
    {
        if (args != null && args.length > 0)
        {
            if (args.length == 2 && args[0].trim().equalsIgnoreCase("server"))
            {
                int port = 0;

                try
                {
                    port = Integer.parseInt(args[1]);
                }
                catch (Exception e)
                {
                    System.err.println(e.getMessage());
                    System.exit(-1);
                }

                Ps1Server.init(port);
                return;
            }
            else
            {
                if (args[0].trim().equalsIgnoreCase("debug"))
                    test(true);
                else test(false);
            }
        }
    }

    private static void test(boolean debug)
    {
        GraphService graphService = new GraphService();

        graphService.setDebug(debug);

        /**********************************
         * Seed Data /
         **********************************/
        graphService.addEdge('A', 'B', 5);
        graphService.addEdge('B', 'C', 4);
        graphService.addEdge('C', 'D', 8);
        graphService.addEdge('D', 'C', 8);
        graphService.addEdge('D', 'E', 6);
        graphService.addEdge('A', 'D', 5);
        graphService.addEdge('C', 'E', 2);
        graphService.addEdge('E', 'B', 3);
        graphService.addEdge('A', 'E', 7);
        /**********************************/

        try
        {
            graphService.caculateDistance("A-B-C");
            graphService.caculateDistance("A-D");
            graphService.caculateDistance("A-D-C");
            graphService.caculateDistance("A-E-B-C-D");
            graphService.caculateDistance("A-E-D");
        }
        catch (NoSuchRouteException e)
        {
            
        }
        

        graphService.countPathsWithMaxStop('C', 'C', 3);
        graphService.countPathsWithExactStop('A', 'C', 4);

        graphService.shortestDistance('A', 'C');
        graphService.shortestDistance('B', 'B');

        graphService.allPathsLessThanDistance('C', 'C', 28);
    }

}
